package contract

import "reflect"

type Asset interface {
	Index() string
	Permission() map[string]Mode
}

type Participant interface {
	Organization() string
}

// transaction
type Transaction interface {
	Transaction() error
	Commit() error
}

type assetCollection struct {
	asset   Asset
	value   reflect.Value
	methods map[string]reflect.Method
}

func newAssetCollection(asset Asset) *assetCollection {
	methods := make(map[string]reflect.Method)
	typ := reflect.TypeOf(asset)
	methodNum := typ.NumMethod()
	for i := 0; i < methodNum; i++ {
		m := typ.Method(i)
		numIn := m.Type.NumIn()
		numOut := m.Type.NumOut()
		if numIn != 1 || numOut != 1 {
			continue
		}
		if m.Type.Out(0).Kind() != reflect.Struct {
			continue
		}
		methods[m.Name] = m
	}
	return &assetCollection{asset: asset, value: reflect.ValueOf(asset), methods: methods}
}
